package com.ct.dao.map.impl;

import com.ct.dao.map.MapQueryFactory;
import com.ct.dao.searching.Query;
import com.ct.dao.searching.hibernate.HqlQuery;
import com.ct.model.map.CarIdentifier;
import com.ct.model.map.GPSData;

import java.util.Map;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 26.10.2009
 * Time: 21:41:13
 * To change this template use File | Settings | File Templates.
 */
public class MapQueryFactoryImpl implements MapQueryFactory{
    
    public Query<CarIdentifier> createPointsIdentifiersQuery() {
        String sql = " select new com.ct.model.map.CarIdentifier(gps.id) from GPSData gps ";
        HqlQuery<CarIdentifier> query = new HqlQuery(sql);
        query.disableUseRowCount();
        return query;  
    }

    public Query<GPSData> createCarDetailsByIdQuery(Long carId){
        String sql = "select gps, count(*) as row_count from GPSData gps where gps.id = :carId";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("carId", carId);

        HqlQuery<GPSData> query = new HqlQuery(sql, params);
        return query;
    }

    public Query<GPSData> createAllCarDetailsQuery(){
        String sql = " select gps ";
        String count = " select count(*) ";
        String whereClause = " from GPSData gps ";

        HqlQuery<GPSData> query = new HqlQuery(sql + whereClause);
        query.setCountQuery(count + whereClause);

        return query;
    }
}
